﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace sy1_9
{
    public partial class Form1 : Form
    {
        // 初始参数
        private int originalX = 20;         // 初始X坐标
        private int originalY = 350;        // 初始Y坐标（左下角）
        private int originalWidth = 100;    // 初始宽度
        private int originalHeight = 100;   // 初始高度
        private float scaleFactor = 1.0f;   // 缩放比例
        private float moveStep = 5;         // 每次上移像素
        private float shrinkRate = 0.99f;   // 每次缩小比例

        public Form1()
        {
            InitializeComponent();
        }

        // 窗体载入时加载图片
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                // 加载背景图和热气球图片（替换为实际路径）
                this.BackgroundImage = Image.FromFile(@"E:\C#\sy1-9\flowers.jpg");
                this.BackgroundImageLayout = ImageLayout.Stretch;
                pictureBoxBalloon.Image = Image.FromFile(@"E:\C#\sy1-9\ballon.png");
            }
            catch (Exception ex)
            {
                MessageBox.Show("图片加载失败：" + ex.Message);
            }
        }

        // 开始按钮：启动动画
        private void btnStart_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            btnStart.Enabled = false; // 防止重复点击
        }

        // 定时器事件：更新气球位置和大小
        private void timer1_Tick(object sender, EventArgs e)
        {
            // 1. 上移气球
            pictureBoxBalloon.Top -= (int)moveStep;

            // 2. 缩小气球（由近及远效果）
            scaleFactor *= shrinkRate;
            pictureBoxBalloon.Width = (int)(originalWidth * scaleFactor);
            pictureBoxBalloon.Height = (int)(originalHeight * scaleFactor);

            // 3. 检查是否飞出窗体2倍高度
            if (pictureBoxBalloon.Bottom < -pictureBoxBalloon.Height)
            {
                ResetBalloon(); // 重置气球
            }
        }

        // 重置气球到初始状态
        private void ResetBalloon()
        {
            timer1.Enabled = false;
            pictureBoxBalloon.Location = new Point(originalX, originalY);
            pictureBoxBalloon.Size = new Size(originalWidth, originalHeight);
            scaleFactor = 1.0f;
            btnStart.Enabled = true; // 允许重新开始
        }
    }
}